package com.dhp.bkapiinterface.controller;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.dhp.bkapiinterface.Utils.GetUtil;
import com.dhp.bkapiinterface.Utils.SSLUtils;
import com.dhp.bkapiinterface.common.BaseResponse;
import com.dhp.bkapiinterface.common.ErrorCode;
import com.dhp.bkapiinterface.common.ResultUtils;
import com.dhp.bkapiinterface.exception.BusinessException;
import com.dhp.bkapiinterface.model.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
public class ExampleInterface {
    @GetMapping("/getNameByGet")
    public BaseResponse<String> getNameByGet(@RequestParam("userName") String userName){
        log.info("我进来了");
        return ResultUtils.success( "你的名字是" + userName);
    }

    @PostMapping("/getNameByPost")
    public BaseResponse<String> getNameByPost(@RequestBody User user){
        return ResultUtils.success("你的名字是" + user.getUserName());
    }

    @GetMapping("/yan/api.php")
    public BaseResponse<String> poisonChicken() {
        String url = "http://api.btstu.cn/yan/api.php";
        String res = GetUtil.doGet(url, null);
        return ResultUtils.success(res);
    }

    @GetMapping("/randomLoveTalk")
    public BaseResponse<String> getRandomLoveTalk(){
        String url = "https://api.uomg.com/api/rand.qinghua?format=json?format=text";
        String love = GetUtil.doGet(url , null);
        return ResultUtils.success(love);
    }

    @GetMapping("/randomTalk")
    public BaseResponse<String> getRandomTalk(){
        String url = "https://api.52vmy.cn/api/wl/yan/qpdh";
        String talk = GetUtil.doGet(url , null);
        return ResultUtils.success(talk);
    }

    @GetMapping("/fortune")
    public BaseResponse<String> getFortune(@RequestParam("msg") String msg){
        if(StringUtils.isEmpty(msg)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR , "msg参数是必须的");
        }
        String url = "https://v.api.aa1.cn/api/xingzuo/";
        Map<String , Object> parameterMap = new HashMap<>();
        parameterMap.put("msg" , msg);
        String res = GetUtil.doGet(url, parameterMap);
        return ResultUtils.success(res);
    }

    @GetMapping("/realIP")
    public BaseResponse<String> getRealIP(){
        String url = "https://myip.tool.hengj.cn/";
        String ip = GetUtil.doGet(url , null);
        return ResultUtils.success(ip);
    }

    @GetMapping("/kfc")
    public BaseResponse<String> KFCThursday(){
        String url = "https://api.52vmy.cn/api/wl/yan/kfc";
        String kfc = GetUtil.doGet(url, null);
        return ResultUtils.success(kfc);
    }

}
